<template>
  <div class="app-container">
    <ueditor-from :content="companyArticleContent" />
    <div style="position: fixed;right: 20px;bottom: 20px">
      <el-button type="primary" @click="addOrUpdate">{{ $t('confirm') }}</el-button>
    </div>
  </div>
</template>

<script>
import UeditorFrom from '@/components/UeditorFrom'
import {
  getCompanyArticleContent,
  insertOrUpdateCompanyArticleContent
} from '@/api/common/commonCompanyArticleContentApi'
import { successNotice } from '@/util/common'

export default {
  name: 'ArticleContent',
  components: {
    UeditorFrom
  },
  data() {
    return {
      companyArticleContent: {},
      articleId: null,
      title: null
    }
  },
  mounted() {
    const param = this.$route.query
    this.articleId = parseInt(param.articleId)
    this.title = param.title
    this.getCompanyArticleContent()
    this.setTagsViewTitle()
  }, methods: {
    setTagsViewTitle() {
      this.tempRoute = Object.assign({}, this.$route)
      const route = Object.assign({}, this.tempRoute, {
        title: `${this.title}`
      })
      this.$store.dispatch('tagsView/updateVisitedView', route)
    },
    getCompanyArticleContent() {
      getCompanyArticleContent({
        articleId: this.articleId
      }).then(res => {
        const { data, code } = res
        if (code === '200') {
          this.companyArticleContent = data
          if (!this.companyArticleContent) {
            this.companyArticleContent = {
              articleId: this.articleId,
              msg: ''
            }
          }
        }
      })
    },
    addOrUpdate() {
      insertOrUpdateCompanyArticleContent({
        ...this.companyArticleContent
      }).then(res => {
        const { code } = res
        if (code === '200') {
          successNotice(this)
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
